-
Notifications
You must be signed in to change notification settings - Fork 129
Create safe realm wrappers #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sagudev
commented
Nov 11, 2025
jdm
reviewed
Nov 11, 2025
Member
jdm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clever! I'm excited to see how these pieces fit together in Servo!
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This allows us to use realm in place of cx without calling any methods as compiler will deref automatically. Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
jdm
approved these changes
Nov 12, 2025
This was referenced Nov 12, 2025
github-merge-queue bot
pushed a commit
to servo/servo
that referenced
this pull request
Nov 16, 2025
#40582) Companion to servo/mozjs#650 We added 3 new options to bindings.conf, each more powerful then the previous one, so one should use the least powerful as possible to keep things flexible: 1 `cx_no_gc` prepends argument `&JSContext`, which allows creating NoGC tokens and using functions that do not trigger GC. 2. `cx` prepends argument `&mut JSContext`, which allows everything that previous one allows, but it also allows calling GC triggering functions. 3. `realm` prepends argument `&mut CurrentRealm`, which can be deref_mut to `&mut JSContext` (so it can do everything that previous can), but it also ensures that there is current entered realm, which can be used for creation of InRealm. next steps: #40600 reviewable per commit Testing: It's just refactoring try run: https://github.com/sagudev/servo/actions/runs/19287700927 --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
github-merge-queue bot
pushed a commit
to servo/servo
that referenced
this pull request
Nov 16, 2025
#40582) Companion to servo/mozjs#650 We added 3 new options to bindings.conf, each more powerful then the previous one, so one should use the least powerful as possible to keep things flexible: 1 `cx_no_gc` prepends argument `&JSContext`, which allows creating NoGC tokens and using functions that do not trigger GC. 2. `cx` prepends argument `&mut JSContext`, which allows everything that previous one allows, but it also allows calling GC triggering functions. 3. `realm` prepends argument `&mut CurrentRealm`, which can be deref_mut to `&mut JSContext` (so it can do everything that previous can), but it also ensures that there is current entered realm, which can be used for creation of InRealm. next steps: #40600 reviewable per commit Testing: It's just refactoring try run: https://github.com/sagudev/servo/actions/runs/19287700927 --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Main usages of using global JSContext in servo are from realms, so with this PR we introduce safe realm concepts that are derived from JSContext (this allows us to enforce LIFO of realms). We also introduce counterpart to servos
AlreadyInRealmandInRealm: https://github.com/servo/servo/blob/main/components/script_bindings/realms.rs. Eventually these new safe types should replace old servo types. Because this change make it hard to use runtime I removed most methods from it.